package com.cm.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @类 名：MyMetaObjectHandler </br>
 * @描 述：</br>
 * @日 期：2020/9/22 21:21</br>
 * @作 者：常明</br>
 * @版 本：1.0.0
 * @since JDK 1.8
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //log.info("-----"+ JSONArray.toJSONString(metaObject));

        //this.setFieldValByName("createDate", LocalDateTime.now(ZoneId.of("+16:00")), metaObject);//@since 快照：3.0.7.2-SNAPSHOT， @since 正式版暂未发布3.0.7
        this.strictInsertFill(metaObject,"createDate",LocalDateTime.class,LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //this.setFieldValByName("updateDate", LocalDateTime.now(ZoneId.of("+16:00")), metaObject);
        log.info("日期更新了");
        this.strictUpdateFill(metaObject, "updateDate",LocalDateTime.class,LocalDateTime.now()); // 起始版本 3.3.3(推荐)
    }
}
